import React, { PureComponent } from 'react';
import {Navigate} from "react-router-dom";

class Login extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      isLogin: false
    }
  }

  login() {
    this.setState({
      isLogin: true
    })
  }

  render() {
    const { isLogin } = this.state
    return ( 
      <div>
        {/* Navigate用于路由的重定向，当这个组件出现时，就会执行跳转到对应的 to 路径中 */}
        <h1>Login</h1>
        {
          isLogin ?  <Navigate to='/home'/> : <button onClick={() => this.login()}>登录</button>
        }
      </div>
     );
  }
}
 
export default Login;